package com.webdev.newtech.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.webdev.newtech.domain.FriendDynamics;
import com.webdev.newtech.service.IFriendDynamicsService;
import com.webdev.newtech.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("friend")
public class FriendDynamicsController {

    //拿到操作数据库的服务实例
    @Autowired
    IFriendDynamicsService dynamicsService;

    @GetMapping("add")
    public AjaxResult add(FriendDynamics dynamics){
        System.out.println(dynamics.toString());
        return AjaxResult.success(dynamicsService.add(dynamics));
    }

    @GetMapping("list")
    public AjaxResult list(Integer pageNum,Integer pageSize){
        pageNum = pageNum == null ? 0 :pageNum;
        pageSize = pageSize == null ? 10 :pageSize;
        System.out.println("获取列表");
        PageHelper.startPage(pageNum,pageSize);
        List<FriendDynamics> list =dynamicsService.getList(null);
        PageInfo info = new PageInfo<FriendDynamics>(list);
        return AjaxResult.success(info);
    }

}
